import re
import time
text3 = "Hello, my email is wangpandong@outlook.com a"
pattern1 = r"(\b[A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+\.(com|cn|org|net|edu|gov|info|biz))\s*.*"
new_text = re.sub(pattern1, r"panda@\2", text3)
new_text2 = re.search(pattern1,text3)
print(new_text)
print(new_text2.group())



#捕获组与非捕获组鹅
import re

text = "400-600-6688"
pattern = r"(\d{3})-(\d{3})-(\d{4})"
s=re.search(pattern,text)
if s:
    s1 = re.sub(pattern, r"86\1\2\3", text)
    print(s1)
else:
    print("the regular expression no match any things")


text = "Hello, my email is wangpandong@outlook.com a"
#提取邮件 （以数字字母开头有@字符，跟多个数字或字母,然后是 .然后再接两个或以上字母或数字）
pattern1 = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b"
match1 = re.search(pattern1, text)
if match1:
    print("Found email:", match1.group())
else:
    print("No email found.")

text2 = '23456wangpandong5968iuohjgbm,li[pw;ef,slfke'
prttern2 = r"\b[a-z][a-z]*\b"
match2 = re.search(prttern2,text2)
if match2:
    print('match2',match2.group())
else:
    print('not match')

prttern3 = r"[a-z][a-z]*"
match3 = re.findall(prttern3,text2)
if match3:
    for match in match3:
        print('match3 = ',match)
else:
    print('not match')

match4 = re.findall(prttern3,text2)
if match4:
        print('match4 = ',match4)
else:
    print('not match')


#替换
text3 = "Hello, my email is wangpandong@outlook.com a"
pattern4 = r"(\b[A-Za-z0-9._%+-]+)@"
new_text = re.sub(pattern4, "panda@", text3)
print(new_text)






